package com.example.ioc.controller;


import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/prop")
public class PropertiesController {

    @Value("${my.key}")
    private  String mykey;
    //properties会自动进行类型转换
    @RequestMapping("/readvalue")
    public String readValue(){
        return "从配置文件中读取配置信息："+mykey;
    }

    //在程序启动之前就会执行
    @PostConstruct
    public void readValue2(){
        System.out.println(("从配置方法中配置信息：" + mykey));
    }
}
